const mutations = {
    //切换语言 后期需要
    switchLang(state, lang) {
        state.currentLang = lang
        Vue.config.lang = lang
        document.cookie = "VR_LANG=" + lang + "; path=/;domain=.snail.com"
            // location.reload()
    },
    //设置当前页面名字
    setPageName(state, name) {
        state.currentPageName = name
    },
    //设置前一页名字 已遗弃
    // setBackPageName(state, name) {
    //     state.backPageName = name
    // },
    //当 search 组件全屏/非全屏时 切换公共头部状态
    toggleHeaderStatus(state, status) {
        state.headerStatus = status
    },
    //切换“微信”页中右上角菜单
    toggleTipsStatus(state, status) {
        if (status == -1) {
            state.tipsStatus = false
        } else {
            state.tipsStatus = !state.tipsStatus
        }
    },
    //增加未读消息数
    addNewMsg(state) {
        state.newMsgCount > 99 ? state.newMsgCount = "99+" : state.newMsgCount++
    },
    //减少未读消息数
    minusNewMsg(state) {
        state.newMsgCount < 1 ? state.newMsgCount = 0 : state.newMsgCount--
    },
    //将消息置顶 待完成
    setMsgStick(state, mid) {

    },
    //取消置顶消息 待完成
    cancelMsgStick(state, mid) {

    },
    //添加商品
    addgoodtoCart(state,good){
      var x=state.cart.length
      var newGood=true;//是否是购物车没有的商品
      for (var i=0;i<x;i++) {
        if(good.uid==state.cart[i].uid){
          state.cart[i].count= state.cart[i].count+ good.count
          newGood=false
        }
      }
      if(newGood==true){
        state.cart.push(good)
      }
    },
    deletegood(state,good){
      var x=state.cart.length
      console.log(x)
      for (var i=0;i<x;i++) {
        if(good.uid==state.cart[i].uid){
          if( state.cart[i].count>1){
            console.log("!")
            state.cart[i].count--;
            return
          }else {
            console.log(state.cart,1)
            console.log(i)
            state.cart.splice(i,1)
            console.log(state.cart,2)
            return
          }
        }
      }
    },
    getgoodinfo(state,v){//商品页面消息处理,在列表页面找到id
      var data= state.goodsinfo
      console.log(state.infopage.title,111)
      for(var i=0;i<data.length;i++){
        if(data[i].id==v){
          console.log( state.infopage)
          state.infopage= data[i]
          console.log( state.infopage.title,333)
        }
      }
    },
    countchange(state,obj){//改变清单页面
      console.log(state.cart)
      var id=obj.id//商品id
      var uid=obj.uid//类别id
      var num=obj.num//增减数量
      var data=state.goodsinfo
      var x=data.length
      for(var i=0;i<x;i++){
        if(id==data[i]){
            for (var z=0;z<data.type.length;z++){
              if(uid==data.type[z].typeid){
                data.type[z].count=data.type[z].typeid-num;
                // data.type[z].stock=data.type[z].typeid+num  //库存逻辑
              }
            }
          // return
        }
      }

    },
    sumbitOrder(state){
        var order={//这条信息应该是服务器返回 故不做处理
            id:123456789,
            state:0,
            goodlist:[
              {
                img:"https://www.baidu.com/img/baidu_jgylogo3.gif",
                uid:456,
              },
              {
                img:"https://www.baidu.com/img/baidu_jgylogo3.gif",
                uid:456,
              },
              {
                img:"https://www.baidu.com/img/baidu_jgylogo3.gif",
                uid:456,
              }
            ],
            totle_prize:400,
            post_prize:0.00
          };
      state.cart=[];
      state.order.push(order)
      var x=state.goodsinfo.length
      for(var i=0;i<x;i++){
        var y= state.goodsinfo[i].type.length
        for(var j=0;j<y;j++){
          state.goodsinfo[i].type[j].count=0
        }
      }
    }

}
export default mutations
